<%--
  Created by IntelliJ IDEA.
  User: yingzi
  Date: 2017-6-15
  Time: 11:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>动态列示例</title>
    <jsp:include page="/static/commonviews/header.jsp"/>

</head>
<body>

<div style="margin: 20px">
    <table id="dgTable"></table>
</div>
<ul id="context-menu" class="dropdown-menu">
    <li class="disabled" data-item="add"><a>新增</a></li>
    <li data-item="edit"><a>修改</a></li>
    <li data-item="delete"><a>删除</a></li>
    <li data-item="copy"><a>拷贝</a></li>
</ul>

<jsp:include page="/static/commonviews/footer.jsp"/>
<script src="resize/colResizable-1.6.js"></script>
<script type="text/javascript" src="bootstrap3-editable/bootstrap-table-contextmenu.min.js"></script>

<script type="text/javascript">
    $(function () {
        $.ajax({
            url:tsUtils.getRootPath()+"/dynamicColumns"
            ,type:'post',
            dataType:'json',
            success:function (result) {
                var colArr=result.objOther;
                var rowsArr=result.rows;
                $("#dgTable").bootstrapTable({
                    dataType: "json",
                  //  height:500,
                    striped:true,
                    pagination:true,
                    resizable:true,//允许拖动
                    showColumns:true,//显示列过滤
                    pageSize:50,
                    sortable:true,
                    contextMenu:"#context-menu",
                    contextMenuAutoClickRow:true,
                    pageList:[5, 10, 50, 100],
                    columns:colArr,
                    data:rowsArr ,
                    onClickRow: function(row, $el){
                        $('#dgTable').find('.success').removeClass('success');
                        $el.addClass('success');
                    }
                    ,onContextMenuItem: function(row, da) {
                        //此次兼容IE8
                        if (da[0].className == "disabled") {
                            return;
                        }
                        if (da.data("item") == "edit") {
                            alert("Edit: " + row.name);
                        } else if (da.data("item") == "delete") {
                            alert("Delete: " + row.Id + ' ' + row.name);
                        } else if (da.data("item") == "add") {
                            alert("add: " + row.Id + ' ' + row.name);
                        } else if (da.data("item") == "copy") {
                            // alert("add: " +  row.Id + ' ' + row.Name);
                            if (window.clipboardData) {
                                window.clipboardData.clearData();
                                window.clipboardData.setData("Text", row.name);
                                alert('恭喜，复制成功！');
                            }

                        }
                    }
                });
                $("#dgTable").colResizable();
            },
            error:function (result) {
                layer.alert(result);
            }
        });


    });
</script>
</body>
</html>
